package com.ld.hpfs.service.impl;

import java.util.ArrayList;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ld.hpfs.dao.DefineReportMapper;
import com.ld.hpfs.service.DefineReportService;

@Service
public class DefineReportServiceImpl implements DefineReportService {

	private static final Logger logger = LoggerFactory
			.getLogger(DefineReportServiceImpl.class);

	@Autowired
	private DefineReportMapper definereportmapper;

	// 获取表名管理一览信息
	@Override
	public ArrayList<HashMap<String, Object>> getReportList(
			HashMap<String, Object> param) {
		int count = definereportmapper.getReportListCount(param);
		if (count == 0) {
			return null;
		} else {
			param.put("pageCount", count);
			return definereportmapper.getReportList(param);
		}
	}

	// 获取表明管理表中已添加表名
	@Override
	public ArrayList<HashMap<String, Object>> getReportTableCN(String cpn_id) {
		return definereportmapper.getReportTableCN(cpn_id);
	}

	// 获取表明管理表中已添加表名
	@Override
	public ArrayList<HashMap<String, Object>> getReportTableEN(String cpn_id) {
		return definereportmapper.getReportTableEN(cpn_id);
	}

	@Override
	public ArrayList<HashMap<String, Object>> getTableField(
			HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		return definereportmapper.getTableField(param);
	}

	@Override
	public ArrayList<HashMap<String, Object>> getUser() {
		// TODO Auto-generated method stub
		return definereportmapper.getUser();
	}

	@Override
	public ArrayList<HashMap<String, Object>> getUserGroup(
			HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		return definereportmapper.getUserGroup(param);
	}

	@Override
	public int ReportDelete(HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		try{
			definereportmapper.ReportDelete(param);
			return 0;
		}catch(Exception ex){
			logger.error(ex.getMessage());
			return -1;
		}
	}

	@Override
	public ArrayList<HashMap<String, Object>> ReportEdit(HashMap<String, Object> param) {
		// TODO Auto-generated method stub
			return definereportmapper.ReportEdit(param);
	}

	//获取用户组下所属用户
	@Override
	public ArrayList<HashMap<String, Object>> getUserIdOfGroup(
			HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		return definereportmapper.getUserIdOfGroup(param);
	}
	//保存报告
	@Override
	public int ReportSave(HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		try{
			definereportmapper.ReportSave(param);
			return 0;
		}catch(Exception ex){
			logger.error(ex.getMessage());
			return -1;
		}
	}

	//获取报告数据
	@Override
	public ArrayList<HashMap<String, Object>> getreportstore(
			HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		return definereportmapper.getreportstore(param);
	}

	//获取报告列
	@Override
	public ArrayList<HashMap<String, Object>> getReportColume(
			HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		return definereportmapper.getReportColume(param);
	}
	//获取报告名称
	@Override
	public ArrayList<HashMap<String, Object>> getReportName() {
		// TODO Auto-generated method stub
		return definereportmapper.getReportName();
	}

	@Override
	public int ReportEditEdit(HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		try{
			definereportmapper.ReportEditEdit(param);
			return 0;
		}catch(Exception ex){
			logger.error(ex.getMessage());
			return -1;
		}
	}

	@Override
	public ArrayList<HashMap<String, Object>> CheckReportUser(
			HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		return definereportmapper.CheckReportUser(param);
	}
	
	
	
	/********************以下为履历添加 ******************************/
	 
	@Override
	public boolean AddDefineReportHistory(HashMap<String, Object> history_param) {
		try{
			ArrayList<HashMap<String, Object>> histories = definereportmapper.getDefineReportForHistory((String) history_param.get("report_hid"));
			for(HashMap<String, Object> history : histories){
				history.put("action", history_param.get("action"));
				history.put("user_id", history_param.get("user_id"));
				history.put("user_name", history_param.get("user_name"));
				history.put("update_time", history_param.get("update_time"));
				definereportmapper.AddDefineReportHistory(history);
			}
			return true;
		}catch(Exception ex){
			logger.error(ex.getMessage());
			return false;
		}
	}

	@Override
	public ArrayList<HashMap<String, Object>> getReportNameForCom() {
		// TODO Auto-generated method stub
		return definereportmapper.getReportNameForCom();
	}

	@Override
	public int getTotalCount(HashMap<String, Object> paramfordata) {
		// TODO Auto-generated method stub
		return definereportmapper.getTotalCount(paramfordata);
	}

	@Override
	public HashMap<String, Object> getFieldProperty(HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		return definereportmapper.getFieldProperty(param);
	}

}
